package com.simon.nvwo.modules.rmi;

import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;

/**
 * 远程调用服务器端
 * @author zhaoyi
 *
 */
public class HelloServer {
	
	
	public static void main(String[] args) {
		   
		try{
			
			//创建远程调用对象
			IHello hello=new HelloImpl();
			//创建本地主机的实例并且绑定接受接口为8888(默认为1009）
			LocateRegistry.createRegistry(8888);
			
			//将远程对象绑定到RMI注册服务器，并命名为RHello
			Naming.bind("rmi://localhost:8888/RHello", hello);
			//Naming.bind("localhost://localhost:8888/RHello", hello);
			
			System.out.println(">>>>>info:远程IHello对象绑定成功");
			
		} catch (RemoteException e) {
            System.out.println("创建远程对象发生异常！");
            e.printStackTrace();
        } catch (AlreadyBoundException e) {
            System.out.println("发生重复绑定对象异常！");
            e.printStackTrace();
        } catch (MalformedURLException e) {
            System.out.println("发生URL畸形异常！");
            e.printStackTrace(); 
        }
	}

}
